/**
 * 通用函数工具类
 */
import { h, computed } from "vue";
import { ElTag, ElIcon, type TagProps } from "element-plus";
import { authStore } from "@/store";
import { useRoute } from "vue-router";

//性别选项
const genderOptions = [
    { label: "男", value: 1, type: "success" },
    { label: "女", value: 2, type: "danger" },
]

//性别渲染
const genderFormat = (row: any, column: any) => {
    const value = genderOptions.filter(item => item.value == row[column.property]);
    if (value && value.length > 0) {
        return h(ElTag, { type: value[0].type as TagProps['type'] }, () => value[0].label);
    }
};

//状态选项
const statusOptions = [
    { label: "启用", value: 1, type: "success" },
    { label: "停用", value: 0, type: "danger" },
]

//状态渲染
const statusFormat = (row: any, column: any) => {
    const value = statusOptions.filter(item => item.value == row[column.property]);
    if (value && value.length > 0) {
        return h(ElTag, { type: value[0].type as TagProps['type'] }, () => value[0].label);
    }
};

//布尔类型的渲染
const boolFormat = (row: any, column: any) => {
    const property = row[column.property];
    if (property == 1) {
        return h(ElTag, { type: "success" }, () => "是");
    } else if (property == 0) {
        return h(ElTag, { type: "danger" }, () => "否");
    }
}

//判断是否有权限
const hasPermission = (value: string): boolean => {
    const store = authStore();
    const route = useRoute();
    const path = route.fullPath;
    const include = computed(() => store.routerResourceList[path]?.includes(value));
    return include.value;
}

//延迟函数，默认1秒
const delay = (ms: number = 1000): Promise<void> => new Promise(resolve => setTimeout(resolve, ms));

//全屏/收缩图标
const extend = () => h(ElIcon, { innerHTML: `<svg t="1760412444996" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8953" width="200" height="200"><path d="M895.4 153.7c0-0.9-0.6-1.8-0.8-2.7s-0.6-2.2-1-3.2a30.7 30.7 0 0 0-1.7-3.1 18.3 18.3 0 0 0-1.3-2.4 30 30 0 0 0-8.9-8.9c-0.7-0.5-1.6-0.9-2.3-1.3l-3.2-2.1a30 30 0 0 0-3.2 0l-3-1.4a33.6 33.6 0 0 0-6.3-0.6H672a32 32 0 0 0 0 64h114.7L553.4 425.4a31.9 31.9 0 0 0 0 45.2 31.9 31.9 0 0 0 45.2 0L832 237.3V352a32 32 0 1 0 64 0V160a33.6 33.6 0 0 0-0.6-6.3zM425.4 553.4L192 786.7V672a32 32 0 1 0-64 0v192a33.6 33.6 0 0 0 0.6 6.3c0 0.9 0.6 1.8 0.8 2.7s0.6 2.2 1 3.2a30.7 30.7 0 0 0 1.7 3.1 18.3 18.3 0 0 0 1.3 2.4 29.1 29.1 0 0 0 8.9 8.9 18.3 18.3 0 0 0 2.4 1.3 30.7 30.7 0 0 0 3.1 1.7l3.2 1 2.7 0.8a33.6 33.6 0 0 0 6.3 0.6h192a32 32 0 0 0 0-64H237.3l233.3-233.4a32 32 0 0 0-45.2-45.2z" fill="#333333" p-id="8954"></path></svg>` })
const shrink = () => h(ElIcon, { innerHTML: `<svg t="1760413201905" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4283" width="200" height="200"><path d="M960.492203 103.534326l-299.801594 298.645594h184.05701c15.317011 0 27.74402 12.354759 27.74402 27.67177 0 15.208636-12.463134 27.563395-27.74402 27.563395h-249.082058c-7.730756 0-14.775136-3.215127-19.832639-8.272631-5.346504-4.551753-8.706131-11.126508-8.706132-19.290764v-248.901432c0-15.208636 12.463134-27.67177 27.744021-27.671771 15.317011 0 27.74402 12.463134 27.74402 27.671771l-0.903126 181.853383 299.54872-298.284344 39.231778 39.015029zM427.684188 872.961264c-15.317011 0-27.74402-12.354759-27.74402-27.563395l0.903126-181.853383-299.54872 298.284343-39.231779-39.159528 299.801595-298.537219H177.80738c-15.317011 0-27.74402-12.354759-27.74402-27.67177 0-15.208636 12.463134-27.59952 27.74402-27.59952l249.082058-0.07225c7.730756 0 14.775136 3.215127 19.832639 8.381006 5.346504 4.515628 8.706131 11.126508 8.706132 19.290764v248.901432c0.036125 15.244761-12.427009 27.59952-27.744021 27.59952z" fill="#231815" p-id="4284"></path></svg>` })

//全屏/收缩图标
const fullscreen = () => h(ElIcon, { innerHTML: `<svg t="1744533000176" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3743" width="200" height="200"><path d="M17.066667 2.844444C11.377778 2.844444 8.533333 5.688889 5.688889 8.533333 2.844444 11.377778 0 14.222222 0 19.911111v364.088889c0 2.844444 0 5.688889 2.844444 5.688889h5.688889l122.311111-122.311111 164.977778 164.977778c2.844444 2.844444 8.533333 5.688889 11.377778 5.688888 5.688889 0 8.533333-2.844444 11.377778-5.688888l110.933333-110.933334c2.844444-2.844444 5.688889-8.533333 5.688889-11.377778 0-5.688889-2.844444-8.533333-5.688889-11.377777l-159.288889-170.666667L389.688889 8.533333c2.844444-2.844444 2.844444-2.844444 0-5.688889 0-2.844444-2.844444-2.844444-2.844445-2.844444L17.066667 2.844444zM17.066667 1024c-5.688889 0-8.533333-2.844444-11.377778-5.688889-2.844444-2.844444-5.688889-8.533333-5.688889-11.377778V640c0-2.844444 0-5.688889 2.844444-5.688889h5.688889l122.311111 122.311111 164.977778-164.977778c2.844444-2.844444 8.533333-5.688889 11.377778-5.688888 5.688889 0 8.533333 2.844444 11.377778 5.688888l110.933333 110.933334c2.844444 2.844444 5.688889 8.533333 5.688889 11.377778s-2.844444 8.533333-5.688889 11.377777l-164.977778 164.977778 119.466667 119.466667c2.844444 2.844444 2.844444 2.844444 0 5.688889 0 2.844444-2.844444 2.844444-5.688889 2.844444L17.066667 1024zM1006.933333 2.844444c5.688889 0 8.533333 2.844444 11.377778 5.688889 2.844444 2.844444 5.688889 5.688889 5.688889 11.377778v364.088889c0 2.844444 0 5.688889-2.844444 5.688889h-5.688889l-122.311111-122.311111-164.977778 164.977778c-2.844444 2.844444-8.533333 5.688889-11.377778 5.688888-5.688889 0-8.533333-2.844444-11.377778-5.688888l-110.933333-110.933334c-2.844444-2.844444-5.688889-8.533333-5.688889-11.377778 0-5.688889 2.844444-8.533333 5.688889-11.377777l164.977778-164.977778L640 14.222222c-2.844444-2.844444-2.844444-2.844444 0-5.688889-5.688889-8.533333-2.844444-8.533333-2.844444-8.533333l369.777777 2.844444z m0 1021.155556c5.688889 0 8.533333-2.844444 11.377778-5.688889 2.844444-2.844444 5.688889-8.533333 5.688889-11.377778V640c0-2.844444 0-5.688889-2.844444-5.688889h-5.688889l-122.311111 122.311111-164.977778-164.977778c-2.844444-2.844444-8.533333-5.688889-11.377778-5.688888-5.688889 0-8.533333 2.844444-11.377778 5.688888l-110.933333 110.933334c-2.844444 2.844444-5.688889 8.533333-5.688889 11.377778s2.844444 8.533333 5.688889 11.377777l164.977778 164.977778-119.466667 119.466667c-2.844444 2.844444-2.844444 2.844444 0 5.688889 0 2.844444 2.844444 2.844444 5.688889 2.844444l361.244444 5.688889z" fill="#ffffff" p-id="3744"></path></svg>` });
const shrinkscreen = () => h(ElIcon, { innerHTML: `<svg t="1744532352750" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8350" width="200" height="200"><path d="M707.669333 828.330667L597.333333 938.666667v-341.333334h341.333334l-110.336 110.336L1024 903.338667 903.338667 1024l-195.669334-195.669333zM120.661333 0L0 120.661333l195.669333 195.669334L85.333333 426.666667h341.333334V85.333333L316.330667 195.669333 120.661333 0z m707.669334 316.330667L938.666667 426.666667h-341.333334V85.333333l110.336 110.336L903.338667 0 1024 120.661333l-195.669333 195.669334zM0 903.338667L120.661333 1024l195.669334-195.669333L426.666667 938.666667v-341.333334H85.333333l110.336 110.336L0 903.338667z" p-id="8351" fill="#ffffff"></path></svg>` });

//试卷小旗标识
const paperFlagSvg = `<svg t="1755741124434" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5745" width="20" height="20"><path d="M0 0.051709h1023.948291v1023.948291H0z" fill="#FFFFFF" fill-opacity="0" p-id="5746"></path><path d="M344.916982 0.256499c164.804477-4.914952 212.520468 75.05541 332.783194 98.452628 107.156189 20.837348 172.023313-57.341104 243.187719-26.213076v459.445598c-293.514778 204.94325-459.650388-148.984476-710.364126 13.106538v334.779894c37.783692 20.376571 62.307253 124.409717-31.998385 137.82344-62.97282 8.959548-113.914247-89.288291-38.39806-137.82344V26.520773c0-0.614369 8.037994-26.366668 31.998384-26.264274 27.441814 0.153592 30.462462 18.123885 44.797737 32.817543 42.647446-10.905049 61.846477-30.820844 127.993537-32.766346z" fill="#D6292A" p-id="5747"></path></svg>`

//加载图标
const loadingSvg = `<path class="path" d=" M 30 15 L 28 17 M 25.61 25.61 A 15 15, 0, 0, 1, 15 30 A 15 15, 0, 1, 1, 27.99 7.5 L 15 15" style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>`;

//退出
const logout = () => h(ElIcon, { size: 21, innerHTML: `<svg t="1762058598941" class="icon" viewBox="0 0 1042 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7097" width="250" height="250"><path d="M581.632 697.344l126.976 0 0 194.56q0 33.792-10.24 58.88t-27.136 40.96-39.424 23.552-48.128 7.68l-452.608 0q-24.576 0-48.128-9.728t-41.472-27.136-29.184-40.96-11.264-52.224l0-706.56q0-24.576 11.776-47.104t30.208-39.936 40.96-28.16 45.056-10.752l449.536 0q26.624 0 50.176 11.776t41.472 29.696 28.16 40.448 10.24 44.032l0 188.416-126.976 0 1.024-195.584-452.608 0-1.024 713.728 452.608 0 0-195.584zM1021.952 505.856q37.888 30.72 2.048 60.416-20.48 15.36-44.544 37.888t-50.176 46.592-51.712 47.616-47.104 40.96q-23.552 18.432-40.448 18.432t-16.896-24.576q2.048-14.336 0.512-35.84t-1.536-36.864q0-17.408-12.288-21.504t-29.696-4.096l-40.96 0-62.464 0q-34.816 0-73.216-0.512t-73.216-0.512l-62.464 0-41.984 0q-8.192 0-17.92-1.536t-17.408-6.656-12.288-14.336-4.608-23.552q0-19.456-0.512-46.08t0.512-47.104q0-27.648 13.312-37.888t43.008-9.216l33.792 0 59.392 0q32.768 0 70.144 0.512t71.168 0.512l61.44 0 38.912 0q25.6 1.024 43.52-4.096t17.92-22.528q0-14.336 1.024-32.256t1.024-32.256q0-23.552 12.8-29.696t32.256 9.216q19.456 16.384 45.568 38.4t52.736 45.056 52.736 45.568 47.616 39.936z" p-id="7098" fill="#ffffff"></path></svg>` })
//人工智能
const artificialIntelligence = () => h(ElIcon, { innerHTML: `<svg t="1762059592136" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9216" width="200" height="200"><path d="M196.1 989.7c-9.1 0-17.6-3.5-24-9.9-6.3-6.3-9.9-15-9.9-24v-236c0-1.9-1.4-3.5-3.3-3.8-39.1-5.1-108.4-19.7-133.7-60.7-12.4-20.1-13.5-44.2-3.1-67.7 27.2-61.2 72.5-105.4 97-126.2 0.7-0.6 1.2-1.5 1.3-2.4 8.9-71.3 71.3-426.8 428.7-426.8 194.6 0 351.9 88.1 420.8 235.5 73.4 157.3 30.3 352.4-118.3 535.4-0.6 0.7-0.8 1.5-0.8 2.4V950c0 18.7-15.2 33.9-33.9 33.9S783 968.7 783 950V791.8c0-8 2.8-15.7 7.9-21.8C929.1 604.9 972 432.1 908.6 296.2c-57.5-123-191.8-196.4-359.4-196.4-336.2 0-361.8 364.6-362.8 380.1-0.7 10.1-5.7 19.4-13.9 25.4-6.3 4.8-60.7 47.3-88.4 109.7-0.4 1-0.4 2.1 0 3 7.1 16.8 65.6 31.1 113.6 33.5 18.1 0.9 32.2 15.7 32.3 33.8V918c0 2.1 1.7 3.8 3.8 3.8h189.3c18.7 0 33.9 15.2 33.9 33.9s-15.2 33.9-33.9 33.9h-227z" fill="#ffffff" p-id="9217"></path><path d="M583.9 687.3c-14.3 0-27.1-9-31.9-22.4l-21.3-62.3c-0.5-1.5-2-2.6-3.6-2.6H415.2c-1.6 0-3.1 1-3.6 2.5L389 665.4c-5.1 12.8-17.5 21.1-31.4 21.1-3.9 0-7.8-0.7-11.5-2-17.2-6.2-26.4-24.7-20.8-42.2l116.3-323.6c4.8-13.4 17.6-22.4 31.9-22.4 14.6 0.1 27.4 9.3 32 22.9l110.7 323.7c5.7 17.4-3.9 36.6-21.3 42.5-3.6 1.3-7.2 1.9-11 1.9z m-111.4-247c-1.6 0-3.1 1-3.6 2.5L438.7 527c-0.4 1.2-0.2 2.5 0.5 3.5s1.9 1.6 3.1 1.6h59c1.2 0 2.4-0.6 3.1-1.6 0.7-1 0.9-2.3 0.5-3.5l-28.8-84.2c-0.5-1.5-1.9-2.5-3.6-2.5z m225 244.5c-18.7 0-33.9-14.7-33.9-32.7V329.3c0-18 15.2-32.7 33.9-32.7s33.9 14.7 33.9 32.7v322.9c-0.1 18-15.3 32.6-33.9 32.6z" fill="#ffffff" p-id="9218"></path></svg>` });
export {
    genderOptions,
    genderFormat,
    statusOptions,
    statusFormat,
    boolFormat,
    hasPermission,
    delay,
    extend,
    shrink,
    fullscreen,
    shrinkscreen,
    paperFlagSvg,
    loadingSvg,
    logout,
    artificialIntelligence
};